using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BLL;
using DTO;

namespace QLSV
{
    public partial class SuaSV : Form
    {
        SINHVIEN sv = new SINHVIEN();
        SinhvienDAL svdal = new SinhvienDAL();
        public SuaSV()
        {
            InitializeComponent();
            lblThongbao.Text = "Nhap ma cua sinh vien can thay doi thong tin, roi nhap nut Find";
            btnFind.Enabled = true;
            btnSave.Enabled = false;
            btnUndo.Enabled = false;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool b = svdal.UpdateSINHVIEN(txtMaSV.Text,txtHo.Text, txtTen.Text ,sv.MaSV);
                if (b)
                {
                    lblThongbao.Text = "Cap nhat thanh cong";
                    btnFind.Enabled = true;
                    btnSave.Enabled = false;
                    btnUndo.Enabled = false;
                }
                else
                    lblThongbao.Text = "Cap nhat that bai";
            }
            catch
            {
                lblThongbao.Text = "Cap nhat that bai";
            }

        }

        private void btnUndo_Click(object sender, EventArgs e)
        {
            lblThongbao.Text = "Nhap ma cua sinh vien can thay doi thong tin, roi nhap nut Find";
            txtTen.Text = "";
            txtHo.Text = "";
            btnFind.Enabled = true;
            btnSave.Enabled = false;
            btnUndo.Enabled = false;
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            lblThongbao.Text = "Nhap nut Save de luu cac thay doi. Nhap nut Undo de thay doi khoa khac";
            sv = svdal.GetSINHVIEN(txtMaSV.Text);
            if (sv != null)
            {
                btnFind.Enabled = false;
                btnSave.Enabled = true;
                btnUndo.Enabled = true;
                txtTen.Text = sv.Ten;
                txtHo.Text = sv.Holot;
            }
            else
                lblThongbao.Text = "Ma sinh vien nay khong co. Hay nhap lai";
        }

   
    }
}